% Benchmark to measure robusteness to our method

% Add Tools to Path
addpath('../../Tools');
% Choose data
workingDir = pwd;
modelName = 'Cat';
%modelName = 'Centaur';
modelsPath = ['../Models/' modelName '/'];
cd(modelsPath);
% -> Source data
[filename, pathname] = uigetfile('*.mat', 'Select the mat file of the source mesh');
dataName = strcat(pathname, filename);
% -> Target data
[filename, pathname] = uigetfile('*.mat', 'Select the mat file of the source mesh');
targetDataName = strcat(pathname, filename);
cd(workingDir);

load (dataName);
nV = size(vertices, 1);
nT = size(triangles, 1);

% Choose number of samples
nSamples = 100;

sampling = randsample(nV, nSamples);

% sample_vi tri bar_1 bar_2 bar_3
MAP = zeros(nSamples, 5);
MAP(:, 1) = sampling;

for i = 1 : nSamples
    disp(['Matching sample ' int2str(i)]);
    % 1. on the Source
    cd '../Source';
    
    main( dataName, sampling(i) );
       
    copyfile 'dataForTrg.mat' '../Target';    
    
    % 2. on the Target
    cd '../Target';           
    
    [userTri, userTriW, cost, elapsedTimeGf, elapsedTimeMatchAndTransfer] = main( dataName, 'dataForTrg.mat' );
    
    MAP(i, 2) = userTri;
    MAP(i, 3:5) = userTriW;
    

end % for samples

cd(workingDir);

save([filename '.MAP.mat'], 'MAP');


